# Description:
#   MLIR Tutorial

load("//mlir:tblgen.bzl", "gentbl_cc_library", "td_library")

licenses(["notice"])

package(default_visibility = ["//visibility:public"])

td_library(
    name = "ToyOpsTdFiles",
    srcs = [
        "include/toy/Ops.td",
    ],
    includes = ["include"],
    deps = [
        "//mlir:FunctionInterfacesTdFiles",
        "//mlir:OpBaseTdFiles",
        "//mlir:SideEffectInterfacesTdFiles",
    ],
)

gentbl_cc_library(
    name = "ToyOpsIncGen",
    tbl_outs = [
        (
            ["-gen-op-decls"],
            "include/toy/Ops.h.inc",
        ),
        (
            ["-gen-op-defs"],
            "include/toy/Ops.cpp.inc",
        ),
        (
            ["-gen-dialect-decls"],
            "include/toy/Dialect.h.inc",
        ),
        (
            ["-gen-dialect-defs"],
            "include/toy/Dialect.cpp.inc",
        ),
    ],
    tblgen = "//mlir:mlir-tblgen",
    td_file = "include/toy/Ops.td",
    deps = [":ToyOpsTdFiles"],
)

cc_binary(
    name = "toyc-ch2",
    srcs = [
        "toyc.cpp",
        "parser/AST.cpp",
        "mlir/MLIRGen.cpp",
        "mlir/Dialect.cpp",
    ] + glob(["include/toy/*.h"]),
    includes = ["include/"],
    deps = [
        ":ToyOpsIncGen",
        "//llvm:Support",
        "//mlir:Analysis",
        "//mlir:IR",
        "//mlir:Parser",
        "//mlir:SideEffectInterfaces",
        "//mlir:Support",
    ],
)
